/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.lidovky.articles.articlesData.jiranova;

import cz.mzk.lidovky.articles.PropertyNames;
import cz.mzk.rehan.commons.PropertyLoader;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Martin Řehánek (rehan@mzk.cz)
 */
public class Requirements {

    public static final Logger logger = Logger.getLogger(Requirements.class.getName());
    private final Set<String> booleanRequirements = new HashSet<String>();

    public Requirements(Properties properties) {
        logger.log(Level.FINEST, "Loading requirements from properties");
        loadRequirement(properties, PropertyNames.REQUIRE_AUTHOR_NOT_EMPTY);
        loadRequirement(properties, PropertyNames.REQUIRE_TITLE_NOT_EMPTY);
        loadRequirement(properties, PropertyNames.REQUIRE_LANGUAGE_NOT_EMPTY);
    }

    private void loadRequirement(Properties properties, String propertyName) {
        PropertyLoader loader   = new PropertyLoader(properties);
        boolean required = loader.loadBoolean(propertyName);
        logger.log(Level.FINEST, "Requirement: ''{0}'': {1}", new Object[]{propertyName, required});
        if (required) {
            booleanRequirements.add(propertyName);
        }
    }

    /**
     *
     * @param propertyStr name of property of the requirement
     * @return true if this requirement exists
     */
    public boolean isRequired(String propertyStr) {
        return booleanRequirements.contains(propertyStr);
    }
}
